package com.bdqn.Di3Zhan;

import com.bdqn.Di3Zhan.entity.Buyer;
import org.apache.log4j.Logger;

import java.lang.reflect.Proxy;

public class IntermediaryJdkProxyFactory {
    private static Logger log = Logger.getLogger(IntermediaryJdkProxyFactory.class);
    public static <T> T create(Object target){
        IntermediaryInvocationHandler handler = new IntermediaryInvocationHandler();

        handler.setTarget(target);

        return (T) Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(),handler);
    }

    public void havealookJdkProxy() throws Exception{
        Buyer buyer = IntermediaryJdkProxyFactory.create(new RealBuyer());

        String result = buyer.havealook();

        log.debug(result);
    }
}
